package cn.com.huzo.service.trade.impl;

import cn.com.huzo.model.entities.trade.InspectionJournalLinesNoOfStyleEntity;
import cn.com.huzo.repository.trade.InspectionJournalLinesMaterialRepository;
import cn.com.huzo.repository.trade.InspectionJournalLinesNoOfStyleRepository;
import huzofw.service.impl.GenericManagerImpl;
import cn.com.huzo.service.trade.InspectionJournalLinesNoOfStyleManager;
import huzofw.common.util.annotations.WriteLog;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 化检日记-款号明细管理服务对象类实现。
 *
 * @author 范学春
 */
@Service("InspectionJournalLinesNoOfStyleManager")
public class InspectionJournalLinesNoOfStyleManagerImpl extends GenericManagerImpl<InspectionJournalLinesNoOfStyleEntity, String>
        implements InspectionJournalLinesNoOfStyleManager {

    @Resource(name = "InspectionJournalLinesMaterialRepository")
    private InspectionJournalLinesMaterialRepository _linesDao;

    @Resource(name = "InspectionJournalLinesNoOfStyleRepository")
    private InspectionJournalLinesNoOfStyleRepository _dao;

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    public Map<String, Object> fetchByHeaderKey(Long headerKey) throws Exception {
        Map<String, Object> rtnValue = new HashMap();

        rtnValue.put("LinesNoOfStyleList", _dao.fetchByHeaderKey(headerKey));
        return rtnValue;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @WriteLog(modelName = "贸易管理→化检日记账款号明细", typeOfOperated = "增加")
    public List<InspectionJournalLinesNoOfStyleEntity> insert(Map<String, Object> matchValue) throws Exception {
        //step 1： 增加款号明细
        Integer rowsAffected = _dao.insert(matchValue);
        //step 2: 增加资材明细
        if (rowsAffected > 0) {
            _linesDao.insert(matchValue);
        }
        // step3: 取得返回值    
        return _dao.fetchByHeaderKey(Long.parseLong(matchValue.get("HeaderKey").toString()));
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @WriteLog(modelName = "贸易管理→化检日记账款号明细", typeOfOperated = "更新")
    public Integer update(List<InspectionJournalLinesNoOfStyleEntity> dataList) throws Exception {
        return _dao.update(dataList);

    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @WriteLog(modelName = "贸易管理→化检日记账款号明细", typeOfOperated = "删除")
    public Map<String, Object> deleteLines(InspectionJournalLinesNoOfStyleEntity instance) throws Exception {
        Map<String, Object> rtnValue = new HashMap();

        Integer rowsAffected = _dao.delete(instance.getLinesId());
        rtnValue.put("LinesNoOfStyleList", _dao.fetchByHeaderKey(instance.getHeaderId()));

        return rtnValue;
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Override
    @WriteLog(modelName = "贸易管理→化检日记账款号明细", typeOfOperated = "批量删除")
    public List<InspectionJournalLinesNoOfStyleEntity> batchDeleteLines(List<InspectionJournalLinesNoOfStyleEntity> dataList) throws Exception {
        Integer rowsAffected = _dao.batchDeleteLines(dataList);
        //if (rowsAffected > 0) {
        //    _linesDao.batchDeleteLinesByNoOfStyleLines(instance);
        //}
        return _dao.fetchByHeaderKey(dataList.get(0).getHeaderId());
    }
}
